<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="资产编号" prop="assetNo">
        <el-input
          v-model="queryParams.assetNo"
          placeholder="请输入资产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别" prop="typeId">
        <div style="width: 194px; display: inline; float: left">
          <treeselect
            v-model="form.typeId"
            :options="eqTypeOptions"
            :show-count="true"
            :clearable="false"
            placeholder="请选择设备类别"
            :normalizer="normalizer"
          />
        </div>
      </el-form-item>
      <el-form-item label="设备状态" prop="eqStatus">
        <el-select
          v-model="queryParams.eqStatus"
          placeholder="请选择设备状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in eqStatusDatas"
            :key="parseInt(dict.value)"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="使用状态" prop="usageStatus">
        <el-select
          v-model="queryParams.usageStatus"
          placeholder="请选择使用状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in usageStatusDatas"
            :key="parseInt(dict.value)"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备等级" prop="level">
        <el-select
          v-model="queryParams.level"
          placeholder="请选择设备等级"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in levelDatas"
            :key="parseInt(dict.value)"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="序列号" prop="serialNo">
        <el-input
          v-model="queryParams.serialNo"
          placeholder="请输入序列号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人" prop="personLiable">
        <el-select
          v-model="queryParams.personLiable"
          placeholder="请选择负责人"
          clearable
          size="small"
        >
          <el-option
            v-for="item in users"
            :key="parseInt(item.id)"
            :label="item.nickname"
            :value="parseInt(item.id)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属部门" prop="deptId">
        <div style="width: 194px; display: inline; float: left">
          <treeselect
            v-model="queryParams.deptId"
            :options="deptOptions"
            :show-count="true"
            :clearable="false"
            placeholder="请选择所属部门"
            :normalizer="normalizer"
          />
        </div>
      </el-form-item>
      <el-form-item label="品牌" prop="brand">
        <el-input
          v-model="queryParams.brand"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商" prop="supplierId">
        <el-select
          v-model="queryParams.supplierId"
          placeholder="请选择供应商"
          clearable
          size="small"
        >
          <el-option
            v-for="item in suppliers"
            :key="parseInt(item.id)"
            :label="item.name"
            :value="parseInt(item.id)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ems:equipment:create']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['ems:equipment:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="设备编号" align="center" prop="id" fixed>
        <template slot-scope="scope">
          <router-link :to="'/ems/eq/detail?id=' + scope.row.id">
            <el-link type="primary">
              <b>{{ scope.row.id }}</b>
            </el-link>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="资产编号" align="center" prop="assetNo" />
      <el-table-column label="设备名称" align="center" prop="name" />
      <el-table-column label="规格型号" align="center" prop="specification" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="类别" align="center" prop="eqType.name" />
      <el-table-column label="设备来源" align="center" prop="source">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.EMS_EQUIPMENT_SOURCE"
            :value="scope.row.source"
          />
        </template>
      </el-table-column>
      <el-table-column label="采购金额" align="center" prop="purchaseAmount" >
        <template slot-scope="scope">
          {{ scope.row.purchaseAmount == null ? null : parseFloat(scope.row.purchaseAmount / 100).toFixed(2) + '元' }}
        </template>
      </el-table-column>
      <el-table-column
        label="购置日期"
        align="center"
        prop="purchaseDate"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.purchaseDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="保修期至"
        align="center"
        prop="warrantyPeriod"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.warrantyPeriod) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="启用时间"
        align="center"
        prop="enableTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enableTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="预计报废日期"
        align="center"
        prop="estimatedLife"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.estimatedLife) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备状态" align="center" prop="eqStatus">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.EMS_EQUIPMENT_STATUS"
            :value="scope.row.eqStatus"
          />
        </template>
      </el-table-column>
      <el-table-column label="使用状态" align="center" prop="usageStatus">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.EMS_USAGE_STATUS"
            :value="scope.row.usageStatus"
            effect="dark"
          />
        </template>
      </el-table-column>
      <el-table-column label="设备等级" align="center" prop="level">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.EMS_EQUIPMENT_LEVEL"
            :value="scope.row.level"
          />
        </template>
      </el-table-column>
      <el-table-column label="序列号" align="center" prop="serialNo" />
      <el-table-column
        label="负责人"
        :formatter="userNicknameFormat"
        align="center"
        prop="personLiable"
      />
      <el-table-column
        label="所属部门"
        :formatter="deptNameFormat"
        align="center"
        prop="deptId"
      />
      <el-table-column label="品牌" align="center" prop="brand" />
      <el-table-column
        label="供应商"
        align="center"
        prop="supplier.name"
        width="150"
      />
      <el-table-column label="附件" align="center" prop="enclosure" />
      <el-table-column label="图片" align="center" prop="image" fixed="left">
        <template slot-scope="scope">
          <el-image
            style="width: 60px; height: 60px"
            :src="scope.row.image"
            fit="fit"
          >
            <div slot="error" class="image-slot">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="技术参数" align="center" prop="parameter" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="父设备" align="center" prop="parentIds" />
      <el-table-column label="子设备" align="center" prop="sonIds" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="180"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ems:equipment:update']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ems:equipment:delete']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" width="740px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="资产编号" prop="assetNo">
          <el-input v-model="form.assetNo" placeholder="请输入资产编号" />
        </el-form-item>
        <el-form-item label="设备名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入设备名称" />
        </el-form-item>
        <el-form-item label="规格型号" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入规格型号" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="标签码" prop="tagCode">
              <el-input v-model="form.tagCode" placeholder="请输入电子标签码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位" prop="unit">
              <el-input v-model="form.unit" placeholder="请输入单位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="类别" prop="typeId">
              <treeselect
                v-model="form.typeId"
                :options="eqTypeOptions"
                :show-count="true"
                :clearable="false"
                placeholder="请选择设备类别"
                :normalizer="normalizer"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备来源" prop="source">
              <el-select
                v-model="form.source"
                placeholder="请选择设备来源"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in eqSourceDatas"
                  :key="parseInt(dict.value)"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="采购金额" prop="purchaseAmount">
              <el-input
                v-model="form.purchaseAmount"
                placeholder="请输入采购金额"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="购置日期" prop="purchaseDate">
              <el-date-picker
                clearable
                v-model="form.purchaseDate"
                type="date"
                value-format="timestamp"
                placeholder="选择购置日期"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="保修期至" prop="warrantyPeriod">
              <el-date-picker
                clearable
                v-model="form.warrantyPeriod"
                type="date"
                value-format="timestamp"
                placeholder="选择保修期至"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="启用时间" prop="enableTime">
              <el-date-picker
                clearable
                v-model="form.enableTime"
                type="date"
                value-format="timestamp"
                placeholder="选择启用时间"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="预计报废日期" prop="estimatedLife">
              <el-date-picker
                clearable
                v-model="form.estimatedLife"
                type="date"
                value-format="timestamp"
                placeholder="请输入预计报废日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备状态" prop="eqStatus">
              <el-select
                v-model="form.eqStatus"
                placeholder="请选择设备状态"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in eqStatusDatas"
                  :key="parseInt(dict.value)"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="使用状态" prop="usageStatus">
              <el-select
                v-model="form.usageStatus"
                placeholder="请选择使用状态"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in usageStatusDatas"
                  :key="parseInt(dict.value)"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备等级" prop="level">
              <el-select
                v-model="form.level"
                placeholder="请选择设备等级"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in levelDatas"
                  :key="parseInt(dict.value)"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="序列号" prop="serialNo">
              <el-input v-model="form.serialNo" placeholder="请输入序列号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="负责人" prop="personLiable">
              <el-select
                v-model="form.personLiable"
                placeholder="请选择负责人"
                clearable
                size="small"
              >
                <el-option
                  v-for="item in users"
                  :key="parseInt(item.id)"
                  :label="item.nickname"
                  :value="parseInt(item.id)"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属部门" prop="deptId">
              <treeselect
                v-model="form.deptId"
                :options="deptOptions"
                :show-count="true"
                :clearable="false"
                placeholder="请选择所属部门"
                :normalizer="normalizer"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="品牌" prop="brand">
              <el-input v-model="form.brand" placeholder="请输入品牌" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="供应商" prop="supplierId">
              <el-select
                v-model="form.supplierId"
                placeholder="请选择供应商"
                clearable
                size="small"
              >
                <el-option
                  v-for="item in suppliers"
                  :key="parseInt(item.id)"
                  :label="item.name"
                  :value="parseInt(item.id)"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="附件" prop="enclosure">
              <el-input v-model="form.enclosure" placeholder="请输入附件" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="图片" prop="enclosure">
          <el-input v-model="form.image" placeholder="请输入图片" />
        </el-form-item>
        <el-form-item label="技术参数" prop="parameter">
          <el-input
            v-model="form.parameter"
            placeholder="请输入技术参数"
            type="textarea"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input
            v-model="form.remarks"
            placeholder="请输入备注"
            type="textarea"
          />
        </el-form-item>
        <el-form-item label="父设备" prop="parentIds">
          <el-transfer
            v-model="form.parentIds"
            :data="equipmentDatas"
            :props="transferProps"
          ></el-transfer>
        </el-form-item>
        <el-form-item label="子设备" prop="sonIds">
          <el-transfer
            v-model="form.sonIds"
            :data="equipmentDatas"
            :props="transferProps"
          ></el-transfer>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  createEquipment,
  updateEquipment,
  deleteEquipment,
  getEquipment,
  getEquipmentPage,
  exportEquipmentExcel,
  listSimpleEquipments,
} from "@/api/ems/equipment";
import { getDictDatas, DICT_TYPE } from "@/utils/dict";
import { listSimpleUsers } from "@/api/system/user";
import { listSimpleDepts, listDept } from "@/api/system/dept";
import { listSimpleEqTypes } from "@/api/ems/eqType";
import { listSimpleSuppliers } from "@/api/ems/supplier";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Equipment",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        assetNo: null,
        name: null,
        typeId: null,
        eqStatus: null,
        usageStatus: null,
        level: null,
        serialNo: null,
        personLiable: null,
        deptId: null,
        brand: null,
        supplierId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "设备名称不能为空", trigger: "blur" },
        ],
        typeId: [
          { required: true, message: "类别不能为空", trigger: "change" },
        ],
        eqStatus: [
          { required: true, message: "设备状态不能为空", trigger: "change" },
        ],
        usageStatus: [
          { required: true, message: "使用状态不能为空", trigger: "change" },
        ],
        level: [
          { required: true, message: "设备等级不能为空", trigger: "change" },
        ],
        personLiable: [
          { required: true, message: "负责人不能为空", trigger: "change" },
        ],
        deptId: [
          { required: true, message: "所属部门不能为空", trigger: "change" },
        ],
      },
      eqStatusDatas: getDictDatas(DICT_TYPE.EMS_EQUIPMENT_STATUS),
      usageStatusDatas: getDictDatas(DICT_TYPE.EMS_USAGE_STATUS),
      levelDatas: getDictDatas(DICT_TYPE.EMS_EQUIPMENT_LEVEL),
      eqSourceDatas: getDictDatas(DICT_TYPE.EMS_EQUIPMENT_SOURCE),
      users: [],
      eqTypeOptions: undefined,
      deptOptions: [],
      suppliers: [],
      equipmentDatas: [],
      transferProps: {
        key: "id",
        label: "name",
      },
      depts: [],
    };
  },
  created() {
    this.getList();
    // 获得用户列表
    listSimpleUsers().then((response) => {
      this.users = response.data;
    });
    listDept().then((response) => {
      this.depts = response.data;
    });
    this.getTreeselect();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = { ...this.queryParams };
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime");
      // 执行查询
      getEquipmentPage(params).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        assetNo: undefined,
        name: undefined,
        specification: undefined,
        tagCode: undefined,
        unit: undefined,
        typeId: undefined,
        source: undefined,
        purchaseAmount: undefined,
        purchaseDate: undefined,
        warrantyPeriod: undefined,
        enableTime: undefined,
        estimatedLife: undefined,
        eqStatus: undefined,
        usageStatus: undefined,
        level: undefined,
        serialNo: undefined,
        personLiable: undefined,
        deptId: undefined,
        brand: undefined,
        supplierId: undefined,
        enclosure: undefined,
        image: undefined,
        parameter: undefined,
        remarks: undefined,
        parentIds: undefined,
        sonIds: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getEquipment(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateEquipment(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createEquipment(this.form).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal
        .confirm('是否确认删除设备编号为"' + id + '"的数据项?')
        .then(function () {
          return deleteEquipment(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime");
      // 执行导出
      this.$modal
        .confirm("是否确认导出所有设备数据项?")
        .then(() => {
          this.exportLoading = true;
          return exportEquipmentExcel(params);
        })
        .then((response) => {
          this.$download.excel(response, "设备.xls");
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    /** 查询类别下拉树结构 + 岗位下拉 */
    getTreeselect() {
      listSimpleEqTypes().then((response) => {
        // 处理 storeOptions 参数
        this.eqTypeOptions = [];
        this.eqTypeOptions.push(...this.handleTree(response.data, "id"));
      });
      listSimpleDepts().then((response) => {
        this.deptOptions.push(...this.handleTree(response.data, "id"));
      });
      listSimpleSuppliers().then((response) => {
        this.suppliers = response.data;
      });
      listSimpleEquipments().then((response) => {
        this.equipmentDatas = response.data;
      });
    },
    // 格式化分类的下拉框
    normalizer(node) {
      return {
        id: node.id,
        label: node.name,
        children: node.children,
      };
    },
    getUser(data) {
      for (const user of this.users) {
        if (data === user.id) {
          return user.nickname;
        }
      }
    },
    getDept(data) {
      for (const dept of this.depts) {
        if (data === dept.id) {
          return dept.name;
        }
      }
    },
    // 部门展示
    deptNameFormat(row, column) {
      if (!row.deptId) {
        return "未设置";
      }
      for (const dept of this.depts) {
        if (row.deptId === dept.id) {
          return dept.name;
        }
      }
      return "未知【" + row.deptId + "】";
    },
    // 用户昵称展示
    userNicknameFormat(row, column) {
      if (!row.personLiable) {
        return "未设置";
      }
      for (const user of this.users) {
        if (row.personLiable === user.id) {
          return user.nickname;
        }
      }
      return "未知【" + row.personLiable + "】";
    },
  },
};
</script>
<style lang="scss">
.image-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background: #f5f7fa;
  color: #909399;
  font-size: 50px;
}
</style>